package net.lainiao.morethread.Chapter4.demo2;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2017/3/3.
 */
public class Task implements Runnable {
    private Date initDate;
    private String name;

    public Task(String name) {
        this.name = name;
        initDate = new Date();


    }

    @Override
    public void run() {
        String thName = Thread.currentThread().getName();
        System.out.println(thName + " Task " + name + " Created on: " + initDate);
        System.out.println(thName + " Task " + name + " Started on: " + new Date());
        Long duration=(long)(Math.random()*10);
        System.out.println(thName+" Task "+name+" Doing a task duration "+ duration+" seconds");
        try {
            TimeUnit.SECONDS.sleep(duration);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(thName+" task "+name+" finished on "+new Date());
    }
}
